package connections;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

/**
 * 
 * @author ran
 * this class is manage the thread that starting the communication in the server side
 */
public class AcceptConn implements Runnable{
	private Socket client;
    private ObjectInputStream in = null;
    private ObjectOutputStream out = null;
    /**
     * class constructor 
     * @param socket
     */
	public AcceptConn(Socket socket) {
		client = socket;
		//reset the in & out stream
		try {
			in = new ObjectInputStream(client.getInputStream());
			out = new ObjectOutputStream(client.getOutputStream());
		} catch (IOException e) {
				e.printStackTrace();
		}	
	}
	
	/**start communication the dialog server - > client
	* Override run method of Runnable 
	*/
	public void run() {
		ReceiveMessageProtocol protocol = new ReceiveMessageProtocol(in, out);
		protocol.run();
		try {
			in.close();
			out.close();
			client.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
